package com.example.springboot.exception;

import com.example.springboot.common.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
public class Exception {
    /**
     *如果抛出的是ServiceException异常 则调用此方法
     * @param se 业务异常
     * @return    Result
     */
    @ExceptionHandler(ServiceException.class)
    @ResponseBody
    public Result handel(ServiceException se){
      return Result.error(se.getCode(), se.getMessage());
    }
}
